<?
class Form{ 
     private $firstselect,$values;
    public function MM_jumpMenu(){
	    return "    <script type=\"text/JavaScript\">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  if (restore) selObj.selectedIndex=0;
}
//-->
    </script>";
	}
	
	public function setFirstselect($firstselect,$values){
	    $this->firstselect = $firstselect;
		$this->values = $values;
	}
	
   // List/Menu Mysql
   // Parameter : คำสั่ง Sql, ชื่อ Object, URL , ค่าของ Selected,  Tag Html
   public function Listmenu_mysql($sql,$obj,$local,$cvalue,$addtage){  
      if($local!="")
         $type = "onchange=MM_jumpMenu('parent',this,0)";
	  
	  if($this->firstselect==""){
	      $firstitem = ".... เลือก ....";
		  $values = "";
	  }else{
	      $firstitem = $this->firstselect;
		  $values = $this->values;
	  }
	  $msg = "<select name='$obj' id='$obj' $type $addtage>";
	  $msg .= "<option value='$values'>$firstitem</option>";
      $result = mysql_query($sql)or die($sql.mysql_error());
      while($fetch = mysql_fetch_array($result)){
         $id = $fetch[0];
         $name = $fetch[1];
         if($id == $cvalue)  $selected = "selected=selected";	
         $msg .= "<option value='$local$id' $selected>$name</option>";
         $selected = ""; //ทำการเคลียร์ค่า selected
      }
      $msg .=  "</select>";
	  return $msg;
	}
	
	// List/Menu Mysql
   // Parameter : คำสั่ง Sql, ชื่อ Object, URL , ค่าของ Selected,  Tag Html
   public function Listmenu_array($arrayvalue,$obj,$local,$cvalue,$addtage){  
      if($local!="")
         $type = "onchange=MM_jumpMenu('parent',this,0)";
	  
	  $msg = "<select name='$obj' id='$obj' $type $addtage>";
	  $msg .= "<option value=''>...เลือก...</option>";
      for($i=0;$i<count($arrayvalue);$i++){
	     $name = $arrayvalue[$i];
		 if($name!=""){
            if($i == $cvalue)  $selected = "selected=selected";	
            $msg .= "<option value='$local$i' $selected>$name</option>";
            $selected = ""; //ทำการเคลียร์ค่า selected
		 }
      }
      $msg .=  "</select>";
	  return $msg;
	}
	
	public function Listmenu_carray($arrayvalue,$obj,$local,$cvalue,$addtage,$carray){  
      if($local!="")
         $type = "onchange=MM_jumpMenu('parent',this,0)";
	  
	  $msg = "<select name='$obj' id='$obj' $type $addtage>";
	  $msg .= "<option value=''>...เลือก...</option>";
      for($i=0;$i<count($arrayvalue);$i++){
	     $name = $arrayvalue[$i];
		 $value = $i;
		 if($name!=""){
		    if($carray==1) $value = $name;
            if($value == $cvalue)  $selected = "selected=selected";	
            $msg .= "<option value='$local$value' $selected>$name</option>";
            $selected = ""; //ทำการเคลียร์ค่า selected
		 }
      }
      $msg .=  "</select>";
	  return $msg;
	}
	
	public function Listmenu_Between($between,$obj,$local,$cvalue,$addtage){  
	  $e = explode(",",$between);
	  $start = $e[0];
	  $end =$e[1];
	  
      if($local!="")
         $type = "onchange=MM_jumpMenu('parent',this,0)";
	  
	  $msg = "<select name='$obj' id='$obj' $type $addtage>";
	  $msg .= "<option value=''>...เลือก...</option>";
      for($i=$start;$i<=$end;$i++){
	     $name = $i;
		 if($name!=""){
            if($i == $cvalue)  $selected = "selected=selected";	
            $msg .= "<option value='$local$i' $selected>$name</option>";
            $selected = ""; //ทำการเคลียร์ค่า selected
		 }
      }
      $msg .=  "</select>";
	  return $msg;
	}
}
?>